home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 3_2004-2005.ISO / Data / Zips / [Math_Grap18194511182004.psc / Math Graph / frmArea.frm < prev    next >
Text File  |  2003-09-29  |  8KB  |  267 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmArea 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Area under curve"
  6.    ClientHeight    =   2850
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   5265
  10.    ControlBox      =   0   'False
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2850
  15.    ScaleWidth      =   5265
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.Frame Frame3 
  18.       Caption         =   "Steps"
  19.       Height          =   615
  20.       Left            =   120
  21.       TabIndex        =   19
  22.       Top             =   1320
  23.       Width           =   2775
  24.       Begin VB.TextBox Text3 
  25.          Height          =   285
  26.          Left            =   720
  27.          TabIndex        =   21
  28.          Text            =   "10000"
  29.          Top             =   240
  30.          Width           =   1935
  31.       End
  32.       Begin VB.Label Label12 
  33.          Caption         =   "Steps="
  34.          Height          =   255
  35.          Left            =   120
  36.          TabIndex        =   20
  37.          Top             =   240
  38.          Width           =   975
  39.       End
  40.    End
  41.    Begin VB.Frame Frame2 
  42.       Caption         =   "Result"
  43.       Height          =   2655
  44.       Left            =   3000
  45.       TabIndex        =   10
  46.       Top             =   120
  47.       Width           =   2175
  48.       Begin VB.Label Label11 
  49.          BackStyle       =   0  'Transparent
  50.          Caption         =   "Integration result:"
  51.          Height          =   255
  52.          Left            =   120
  53.          TabIndex        =   18
  54.          Top             =   1440
  55.          Width           =   1215
  56.       End
  57.       Begin VB.Label Label10 
  58.          BackColor       =   &H00FFFFFF&
  59.          BorderStyle     =   1  'Fixed Single
  60.          Height          =   255
  61.          Left            =   120
  62.          TabIndex        =   17
  63.          Top             =   1680
  64.          Width           =   1935
  65.       End
  66.       Begin VB.Label Label9 
  67.          BackColor       =   &H00FFFFFF&
  68.          BorderStyle     =   1  'Fixed Single
  69.          Height          =   255
  70.          Left            =   120
  71.          TabIndex        =   16
  72.          Top             =   2280
  73.          Width           =   1935
  74.       End
  75.       Begin VB.Label Label8 
  76.          BackStyle       =   0  'Transparent
  77.          Caption         =   "Total (absolute area):"
  78.          Height          =   255
  79.          Left            =   120
  80.          TabIndex        =   15
  81.          Top             =   2040
  82.          Width           =   1575
  83.       End
  84.       Begin VB.Label Label7 
  85.          BackColor       =   &H00FFFFFF&
  86.          BorderStyle     =   1  'Fixed Single
  87.          Height          =   255
  88.          Left            =   120
  89.          TabIndex        =   14
  90.          Top             =   1080
  91.          Width           =   1935
  92.       End
  93.       Begin VB.Label Label6 
  94.          BackStyle       =   0  'Transparent
  95.          Caption         =   "Area below axis:"
  96.          Height          =   255
  97.          Left            =   120
  98.          TabIndex        =   13
  99.          Top             =   840
  100.          Width           =   1335
  101.       End
  102.       Begin VB.Label Label5 
  103.          BackColor       =   &H00FFFFFF&
  104.          BorderStyle     =   1  'Fixed Single
  105.          Height          =   255
  106.          Left            =   120
  107.          TabIndex        =   12
  108.          Top             =   480
  109.          Width           =   1935
  110.       End
  111.       Begin VB.Label Label4 
  112.          BackStyle       =   0  'Transparent
  113.          Caption         =   "Area over axis:"
  114.          Height          =   255
  115.          Left            =   120
  116.          TabIndex        =   11
  117.          Top             =   240
  118.          Width           =   1095
  119.       End
  120.    End
  121.    Begin MSComctlLib.ProgressBar ProgressBar1 
  122.       Height          =   270
  123.       Left            =   120
  124.       TabIndex        =   9
  125.       Top             =   2505
  126.       Width           =   2775
  127.       _ExtentX        =   4895
  128.       _ExtentY        =   476
  129.       _Version        =   393216
  130.       Appearance      =   1
  131.    End
  132.    Begin VB.CommandButton Command2 
  133.       Caption         =   "Close"
  134.       Height          =   375
  135.       Left            =   1560
  136.       TabIndex        =   8
  137.       Top             =   2040
  138.       Width           =   1335
  139.    End
  140.    Begin VB.CommandButton Command1 
  141.       Caption         =   "Calculate area"
  142.       Height          =   375
  143.       Left            =   120
  144.       TabIndex        =   7
  145.       Top             =   2040
  146.       Width           =   1335
  147.    End
  148.    Begin VB.Frame Frame1 
  149.       Caption         =   "Interval"
  150.       Height          =   615
  151.       Left            =   120
  152.       TabIndex        =   2
  153.       Top             =   600
  154.       Width           =   2775
  155.       Begin VB.TextBox Text2 
  156.          Height          =   285
  157.          Left            =   1920
  158.          TabIndex        =   6
  159.          Top             =   240
  160.          Width           =   735
  161.       End
  162.       Begin VB.TextBox Text1 
  163.          Height          =   285
  164.          Left            =   600
  165.          TabIndex        =   4
  166.          Top             =   240
  167.          Width           =   735
  168.       End
  169.       Begin VB.Label Label3 
  170.          Caption         =   "To:"
  171.          Height          =   255
  172.          Left            =   1560
  173.          TabIndex        =   5
  174.          Top             =   240
  175.          Width           =   495
  176.       End
  177.       Begin VB.Label Label2 
  178.          Caption         =   "From:"
  179.          Height          =   255
  180.          Left            =   120
  181.          TabIndex        =   3
  182.          Top             =   240
  183.          Width           =   615
  184.       End
  185.    End
  186.    Begin VB.ComboBox Combo1 
  187.       Height          =   315
  188.       Left            =   840
  189.       TabIndex        =   0
  190.       Top             =   240
  191.       Width           =   2055
  192.    End
  193.    Begin VB.Label Label1 
  194.       Caption         =   "Function:"
  195.       Height          =   255
  196.       Left            =   120
  197.       TabIndex        =   1
  198.       Top             =   240
  199.       Width           =   1215
  200.    End
  201. End
  202. Attribute VB_Name = "frmArea"
  203. Attribute VB_GlobalNameSpace = False
  204. Attribute VB_Creatable = False
  205. Attribute VB_PredeclaredId = True
  206. Attribute VB_Exposed = False
  207.  
  208. Private Sub Command1_Click()
  209. On Error GoTo errh
  210. Dim expression As String
  211. Dim x0 As Double, xN_1 As Double, xN As Double
  212. Dim x2j_1 As Double, x2j As Double
  213. Dim j As Long, N1 As Long
  214. expression = EditedEqu(Combo1.Text)
  215. Call frmMain.Init(expression)
  216. x0 = Stringval(Text1.Text) 'Start x0
  217. xN = Stringval(Text2.Text) 'End xN
  218. N1 = Val(Text3.Text)
  219. h = (xN - x0) / N1 'Distance between two points
  220.  
  221.     xN_1 = x0 + (N1 - 1) * h 'Calculate x[N-1]
  222.     Int1 = GetVal(x0, 0) + 4 * GetVal(xN_1, 0) + GetVal(xN, 0)    'Calculate f(x0)+4*f(x[N-1])+f(xN)
  223.     Int2 = Abs(GetVal(x0, 0)) + 4 * Abs(GetVal(xN_1, 0)) + Abs(GetVal(xN, 0))    'Calculate f(x0)+4*f(x[N-1])+f(xN)
  224.    
  225.     sum1 = 0 'Set the Sum[j=1 -> (N/2)-1](2*f(x[2j-1]+f(x[2j]) to zero
  226.     Sum2 = 0
  227.     For j = 1 To (N1 / 2 - 1)
  228.         x2j_1 = x0 + (2 * j - 1) * h 'Calculate x[2j-1]
  229.         x2j = x0 + (2 * j) * h  'Calculate x[2j]
  230.         x2j_1aa = GetVal(x2j_1, 0)
  231.         x2jaa = GetVal(x2j, 0)
  232.  
  233.         sum1 = sum1 + 2 * x2j_1aa + x2jaa
  234.         Sum2 = Sum2 + 2 * Abs(x2j_1aa) + Abs(x2jaa)
  235.     prog = (j - 1) / ((N1 / 2 - 1) - 1) * 100
  236.     ProgressBar1.Value = prog
  237.     
  238.     Next j
  239.     sum1 = h / 3 * (Int1 + 2 * sum1)
  240.     Sum2 = h / 3 * (Int2 + 2 * Sum2)
  241. over = (sum1 + Sum2) / 2
  242. under = Sum2 - over
  243. Label5.Caption = Format(Str(Round(over, 6)), cstrcoordformat)
  244. Label7.Caption = Format(Str(Round(under, 6)), cstrcoordformat)
  245. Label10.Caption = Format(Str(Round(sum1, 6)), cstrcoordformat)
  246. Label9.Caption = Format(Str(Round(Sum2, 6)), cstrcoordformat)
  247. errh:
  248. x2j_1aa = 0
  249. x2jaa = 0
  250. Resume Next
  251. End Sub
  252.  
  253. Private Sub Command2_Click()
  254. Unload Me
  255. End Sub
  256.  
  257. Private Sub Form_Load()
  258. For i = 1 To numfunctions
  259. If AllFunctions(i).Type = "normal" Then
  260. Combo1.AddItem AllFunctions(i).expression1
  261. End If
  262. Next
  263. Text1.Text = Str(pLeft)
  264. Text2.Text = Str(pRight)
  265.  
  266. End Sub
  267.